package com.lune.job.framework.mvc;

import com.lune.job.framework.exception.AuthException;
import com.lune.job.framework.exception.TokenException;
import com.lune.job.pojo.RespBean;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 **/
@ControllerAdvice
public class GlobalControllerAdvice {


    @ExceptionHandler(TokenException.class)
    @ResponseBody
    public RespBean handle(TokenException exception){
        return RespBean.tokenError("超时或者不合法的token");
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public RespBean handle(RuntimeException exception){
        exception.printStackTrace();
        return RespBean.tokenError("异常错误");
    }

    @ExceptionHandler(AuthException.class)
    @ResponseBody
    public RespBean handle(AuthException exception){
        exception.printStackTrace();
        return RespBean.error(exception.getMessage());
    }
}
